<!-- 规则管理 -->
<template>
  <page-header-wrapper>
    <a-card class="table-card">
      <GzSearchForm :searchFunc="searchFunc" :resetFunc="()=>{searchData = {}}">
        <a-form-item class="table-search-item">
          <a-select v-model:value="searchData['activityTypeId']" placeholder="活动类型" :options="vdata['activityType']" :field-names="{ label: 'activityTypeName', value: 'activityTypeId' }"/>
        </a-form-item>
        <GzTextUp placeholder="审批机构号" v-model:value="searchData['agentNo']"/>
        <a-form-item class="table-search-item">
          <a-select placeholder="是否为抄送" v-model:value="searchData['isCopy']">
            <a-select-option value="">全部</a-select-option>
            <a-select-option :value="0">是</a-select-option>
            <a-select-option :value="1">否</a-select-option>
          </a-select>
        </a-form-item>
      </GzSearchForm>

      <!-- 列表渲染 -->
      <GzTable
        ref="infoTableRef"
        :init-data="true"
        :req-table-data-func="reqTableDataFunc"
        :table-columns="tableColumns"
        :search-data="searchData"
      >
        <template #topBtnSlot>
          <a-button v-if="$access('ENT_ACTIVITY_RULE_INFO_ADD')" type="primary" @click="addOrEditFunc(false)">
            <plus-outlined />新建
          </a-button>
        </template>
        <template #bodyCell="{ column, record }">
          <template v-if="column.key == 'isCopy'">
            <template v-if="record.isCopy === 0">是</template>
            <template v-if="record.isCopy === 1">否</template>
            <!-- <a-switch v-model:checked="record['checked']" /> -->
          </template>
          <template v-if="column.key === 'operation'">
            <a-button v-if="$access('ENT_ACTIVITY_RULE_INFO_EDIT')" type="link" @click="addOrEditFunc(record)">修改</a-button>
            <a-button v-if="$access('ENT_ACTIVITY_RULE_INFO_DEL')" type="link" danger @click="delFunc(record.examineConfigId)">删除</a-button>
          </template>
        </template>

      </GzTable>
    </a-card>
    <AddOrEdit ref="addOrEditRef" :callbackFunc="searchFunc"/>
  </page-header-wrapper>
</template>

<script lang="ts" setup>
import AddOrEdit from "./AddOrEdit.vue";
import { req, API_URL_EXAMINE_CONFIG, API_URL_EXAMINE_CONFIG_REMOVE, API_URL_ACTIVITY_TYPE } from "@/api/manage";
import { ref, reactive, getCurrentInstance } from 'vue'
const { $infoBox, $access } = getCurrentInstance()!.appContext.config.globalProperties

const infoTableRef = ref()
const addOrEditRef = ref()

const vdata:any = reactive({

})

let tableColumns = reactive([
  { key: 'activityTypeName', title: '活动类型',dataIndex: 'activityTypeName', fixed: 'left', },
  { key: 'agentNo', title: '审批机构号',dataIndex: 'agentNo', },
  { key: 'examineOrder', title: '审批顺序',dataIndex: 'examineOrder', },
  { key: 'isCopy', title: '是否为抄送',dataIndex: 'isCopy', },
  { key: 'createdUid', title: '创建者ID',dataIndex: 'createdUid', },
  { key: 'operation', title: '操作', dataIndex: 'operation', fixed: 'right', align: 'center' }
])

const searchData:any = ref({})

// 请求table接口数据
function reqTableDataFunc(params: any) {
  return req.list(API_URL_EXAMINE_CONFIG,params)
}

function searchFunc() {
  infoTableRef.value.refTable(true)
}
// 新增修改
function addOrEditFunc(record){
  addOrEditRef.value.show(record)
}
// 删除审批规则
function delFunc(examineConfigId){
  $infoBox.confirmDanger('确认删除？', '请确认是否删除当前审批规则？', () => {
    req.add(API_URL_EXAMINE_CONFIG_REMOVE,{ examineConfigId }).then(res => {
      $infoBox.message.success('删除成功！')
      infoTableRef.value.refTable(true)
    })
  })
}

// 获取活动类型
function getActivityType(){
  req.list(API_URL_ACTIVITY_TYPE,{}).then(res => {
    vdata.activityType = res.records
  })
}
getActivityType()
</script>
